//
//  TFToast.swift
//  TalkfunSDKDemo
//
//  Created by 莫瑞权 on 2022/5/6.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit

class TFToast: UILabel {
    @objc public let spacingView = UIView()
    @objc public let leftView = UIView()
    @objc public let rightView = UIView()
    @objc public var maskPath:UIBezierPath?
    @objc public var rightMaskPath:UIBezierPath?
    @objc public var label_Frame = CGRect(x: 0, y: 0, width: 0, height: 0)
    
    override init(frame: CGRect) {
        super.init(frame: frame)
 
        self.addSubview(self.leftView)
        
        self.spacingView.backgroundColor = UIColor.white
        self.addSubview(self.spacingView)
        
        self.addSubview(self.rightView)
         
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.spacingView.frame = CGRect(x: -10, y: 0, width: 11, height: self.frame.size.height)
        
        self.leftView.frame = CGRect(x: -18.5, y: 0, width: 9.5, height: self.frame.size.height)
        self.leftView.alpha = 1.0
        self.leftView.backgroundColor = UIColor(red: 58/255.0, green: 201/255.0, blue: 171/255.0, alpha: 1)
        self.bringSubviewToFront(self.leftView)
        self.bringSubviewToFront(self.spacingView)

        if (self.maskPath==nil) {

            self.maskPath = UIBezierPath.init(roundedRect: self.leftView.bounds, byRoundingCorners:[UIRectCorner.topLeft,UIRectCorner.bottomLeft], cornerRadii: CGSize(width: 3, height: 3))
            let maskLayer = CAShapeLayer()
            maskLayer.frame = self.leftView.bounds
            maskLayer.path = self.maskPath!.cgPath
             self.leftView.layer.mask = maskLayer
            
        }
        
     
        self.rightView.frame = CGRect(x: self.frame.size.width-2, y: 0, width: 12, height: self.frame.size.height)
     
        self.rightView.backgroundColor = UIColor.white
        self.bringSubviewToFront(self.rightView)
       
        if (self.rightMaskPath==nil) {
          
            self.rightMaskPath = UIBezierPath.init(roundedRect: self.rightView.bounds, byRoundingCorners:[UIRectCorner.topRight,UIRectCorner.bottomRight], cornerRadii: CGSize(width: 3, height: 3))
            
            let  maskLayer = CAShapeLayer()
            maskLayer.frame = self.rightView.bounds
            maskLayer.path = self.rightMaskPath!.cgPath
            
            self.rightView.layer.mask = maskLayer
           
        }
        
    }

}
